package com.lagou.framework.container;

import com.lagou.framework.common.Request;
import com.lagou.framework.common.Response;
import com.lagou.framework.config.XmlServerConfig;
import com.lagou.framework.coyote.EndPoint;

import java.io.IOException;

/**
 * @author srh
 * @date 2020/04/03
 **/
public class Service {

    private static Service service = new Service();

    public static Service getInstance() {
        return service;
    }

    public void init(XmlServerConfig.Service service) {
        // 初始化容器
        Engine.getInstance().init(service.getEngine());
        // 初始化 coyote 连接器组件
        EndPoint.getInstance().init(service.getConnector());
    }

    public void doService(Request request, Response response) throws IOException {
        Engine.getInstance().doService(request, response);
    }

    public void start() throws IOException {
        EndPoint.getInstance().start();
    }
}
